<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class Transaction extends ActiveRecord
{
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	public function tableName()
	{
		return 'vh_transaction';
	}
	
	public function rules()
	{
		return array(
		);
	}

	public function getByInvest($investId)
	{
            $query = '
                SELECT id, withdraw, fee, (withdraw - fee) as received, IF(isRCB=1,"x","") as isRCB, createdDate
                FROM vh_transaction
                WHERE investId = :investId
                ORDER BY createdDate DESC
            ';

            $result = $this -> executeAllTotal($query, array(':investId' => $investId), false);

            return $result;
	}
        
        public function createTable()
	{
            $query = "
                CREATE TABLE `vh_transaction` (
                `id` int(11) NOT NULL AUTO_INCREMENT,
                `hyipId` int(11) NOT NULL,
                `investId` int(11) NOT NULL,
                `withdraw` float NOT NULL,
                `createdDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                PRIMARY KEY (`id`)
              ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8
            ";
            
            $result = $this -> executeNone($query);

            return $result;
	}
}